package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
)

var (
	id   int
	name string
	age  int
)

func main() {
	db, err := sql.Open("mysql", "vagrant:vagrant@tcp(127.0.0.1:3306)/test?charset=utf8")
	if err != nil {
		panic(err)
		return
	}
	defer db.Close()

	// 查一条
	select_sql := "select id,name,age from user"

	row, err := db.Query(select_sql)
	if err != nil {
		fmt.Println("错了");
		return
	}

	for row.Next() {
		if err = row.Scan(&id, &name, &age); err != nil {
			fmt.Println("没有取到")
			return
		}
		fmt.Println(id, name, age)
	}

}
